In Java, A BigDecimal "bug" that causes double Precision loss, bigdecimaldouble
Background
In the blog's disgusting 0.5 rounding question, I saw a question about 0.5 incorrect rounding. It is mainly said that after double is converted to BigDecimal,
Due to improper use of float or double, there may be an issue of loss of precision. The problem probably can be understood by the following code : [Java]View Plaincopyprint?
Public class Floatdoubletest {
Public static void Main (string[] args)
BackgroundIn the blog disgusting 0.5 rounding problem article see a question about 0.5 not rounding correctly. The main thing is that a double conversion to BigDecimal does not result in the correct rounding: Public class bigdecimaltest {
This article explains why the range of float is larger than int (same as 4 bytes), but some int is not correctly expressed by float (loss of precision)The precision problem of float and double in Java1. Background KnowledgeIn Java there is no detail,
Title in Java accurate calculation of floating-point number Ayellow (original) modificationKeyword Java floating-point number accurate calculationThe question is raised:What will we see if we compile and run the following program?public class
background
In the blog disgusting 0.5 rounding problem in the article see a question about 0.5 not correct rounding. The main thing is that after the double conversion to BigDecimal, rounding does not get the correct result:
public class
1.1 Data TypesData types in Java are divided into two types: basic data type and reference data type. As for the reference type, we will gradually understand it in the subsequent study, which is not covered here, and focuses on the basic data types.
(Its tool class is in the project Arith Util )Original URL:http://blog.csdn.net/pttaag/article/details/5912171First, the previous case: public class test{ public static void main (String Args[]) { system.out.println (0.05+0.01);
I. Loss of precision in floating-point calculationsProbably a lot of friends with programming experience are not familiar with this problem: no matter what programming language you use, when you use floating-point data for accurate calculations, you
This article is divided into three parts
Some typical problems of JS digital precision loss
The reason for the loss of JS digital precision
Solution (one object + one function)
Some typical problems of JS digital precision loss
1.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.